package edu.uestc.gene.ui.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

import edu.uestc.gene.ui.util.ShellUtil;

public class DataComposite extends Composite {

	protected TabFolder tf;
	protected TabItem dg, da, singleGeneResult, doubleGeneResult;
	protected List dg_list, da_list;
	protected Table singleResultTable, doubleResultTable;
	protected Label singleGene_label, doubleGene_label, singleResult_label;

	public DataComposite(Composite parent, int style) {
		super(parent, style);
		this.setLayout(new FillLayout());
		draw();
	}

	public void draw() {
		tf = new TabFolder(this, SWT.BORDER);
		dg = new TabItem(tf, 0);
		dg.setText("D-G表");
		dg_list = new List(tf, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL
				| SWT.H_SCROLL);
		// dg_text.setText("请先录入D-G表");
		dg.setControl(dg_list);

		da = new TabItem(tf, 0);
		da.setText("D-A表");
		da_list = new List(tf, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL
				| SWT.H_SCROLL);
		// da_text.setText("请先录入D-A表");
		da.setControl(da_list);

		singleGeneResult = new TabItem(tf, 0);
		singleGeneResult.setText("单基因统计结果");
		singleGeneResult.setControl(drawSingleResult(tf));

		doubleGeneResult = new TabItem(tf, 0);
		doubleGeneResult.setText("双基因统计结果");
		doubleGeneResult.setControl(drawDoubleResult(tf));
	}

	private Composite drawSingleResult(TabFolder tf) {
		Composite com = new Composite(tf, 0);
		com.setLayout(new GridLayout(2, false));
		Label gene = new Label(com, 0);
		gene.setText("查询基因:");
		singleGene_label = new Label(com, 0);
		singleGene_label.setLayoutData(ShellUtil.getData1(1, 1));

		Label result = new Label(com, 0);
		result.setText("统计结果:");
		singleResult_label = new Label(com, 0);
		singleResult_label.setLayoutData(ShellUtil.getData1(1, 1));

		singleResultTable = new Table(com, SWT.SINGLE | SWT.V_SCROLL | SWT.WRAP);
		singleResultTable.setLinesVisible(true);
		singleResultTable.setHeaderVisible(true);
		singleResultTable.setLayoutData(ShellUtil.getData2(2, 1));
		String[] headers = { "序号", "副作用", "数量", "概率", "对应药物名称" };
		int[] widths = { 60, 80, 60, 100, 600 };
		for (int i = 0; i < headers.length; i++) {
			TableColumn column = new TableColumn(singleResultTable, 0);
			column.setText(headers[i]);
			column.setWidth(widths[i]);
		}
		return com;
	}

	private Composite drawDoubleResult(TabFolder tf) {
		Composite com = new Composite(tf, 0);
		com.setLayout(new GridLayout(2, false));
		Label gene = new Label(com, 0);
		gene.setText("查询基因:");
		doubleGene_label = new Label(com, 0);
		doubleGene_label.setLayoutData(ShellUtil.getData1(1, 1));

		Label result = new Label(com, 0);
		result.setText("统计结果:");
		result.setLayoutData(ShellUtil.getData3(2, 1));

		doubleResultTable = new Table(com, SWT.SINGLE | SWT.V_SCROLL | SWT.WRAP);
		doubleResultTable.setLinesVisible(true);
		doubleResultTable.setHeaderVisible(true);
		doubleResultTable.setLayoutData(ShellUtil.getData2(2, 1));
		String[] headers = { "序号", "副作用", "数量", "概率", "对应药物种类名称" };
		int[] widths = { 60, 80, 60, 100, 600 };
		for (int i = 0; i < headers.length; i++) {
			TableColumn column = new TableColumn(doubleResultTable, 0);
			column.setText(headers[i]);
			column.setWidth(widths[i]);
		}
		return com;
	}

	public void setSelection(int index) {
		tf.setSelection(index);
	}

	@Override
	protected void checkSubclass() {
	}

	public List getDg_list() {
		return dg_list;
	}

	public List getDa_list() {
		return da_list;
	}

	public Table getDoubleResultTable() {
		return doubleResultTable;
	}

	public Label getSingleResult_label() {
		return singleResult_label;
	}

	public TabItem getSingleGeneResult() {
		return singleGeneResult;
	}

	public TabItem getDoubleGeneResult() {
		return doubleGeneResult;
	}

	public Table getSingleResultTable() {
		return singleResultTable;
	}

	public Label getSingleGene_label() {
		return singleGene_label;
	}

	public Label getDoubleGene_label() {
		return doubleGene_label;
	}

}
